<template>
	<div class="login" v-loading.fullscreen.lock="loading">
		<div class="loginBox">
			<h2>用户登录</h2>
			<div class="inputBox">
				<div class="inputText">
					<i class="el-icon-user"></i>
					<input type="text" v-model="username" placeholder="账号" />
				</div>
				<div class="inputText">
					<i class="el-icon-lock"></i>
					<input type="password" v-model="password" placeholder="密码" />
				</div>
				<button class="inputButton" @click="loginClick">登录</button>
			</div>
			<div class="registBox" @click="registClick">
				<div class="spanBox"><span>注册</span></div>
			</div>
		</div>
	</div>
</template>

<script>
export default {
	data() {
		return {
			username: '',
			password: '',
			loading: false
		};
	},
	components: {},
	created() {
		this.initMessage();
	},
	methods: {
		async loginClick() {
			this.loading = true;
			if (this.username === '' || this.password === '') {
				this.$msg.warning('请输入账号或密码！');
				this.loading = false;
				return;
			}
			if (this.username !== '' && this.password !== '') {
				let params = '?userName=' + this.username + '&password=' + this.password;
				const res = await this.$https.postXform('Login' + params);
				if (res.data.Data) {
					sessionStorage.setItem('username', this.username);
					sessionStorage.setItem('password', this.password);
					sessionStorage.setItem('token', res.data.Data);
					this.$router.push('/home');
					return;
				}
				if (!res.data.Data) {
					this.$msg.error('账号或密码错误！');
				}
				this.loading = false;
			}
		},
		registClick() {
			this.$router.push('/regist');
		},
		initMessage() {
			this.username = sessionStorage.getItem('username');
			this.password = sessionStorage.getItem('password');
		}
	}
};
</script>

<style scoped="scoped">
.login {
	position: fixed;
	width: 100%;
	height: 100%;
	background-size: cover;
	display: inline-block;
	background-repeat: no-repeat;
	background-size: cover;
	background: url(../assets/back.jpg);
}

.loginBox {
	margin: 0 auto;
	margin-top: 200px;
	padding: 20px 50px;
	background-color: #000000ee;
	box-shadow: 0 0 20px 0px #000;
	width: 450px;
	height: 300px;
	border-radius: 15px;
	text-align: center;
	position: relative;
	overflow: hidden;
}

.loginBox h2 {
	color: white;
}

.loginBox .inputBox {
	margin-top: 50px;
}

.loginBox .inputBox .inputText {
	margin-top: 20px;
}

.loginBox .inputBox .inputText i {
	color: white;
	font-size: 16px;
	margin-right: 5px;
	vertical-align: center;
}

.loginBox .inputBox .inputText input {
	outline: none;
	border: 0px;
	border-radius: 10px;
	box-shadow: inset -10px -10px 20px 0 rgba(255, 255, 255, 0.9), inset 10px 10px 20px 0 rgba(0, 0, 0, 0.3);
	padding: 10px 10px;
	background-color: #ffffff;
	color: black;
	vertical-align: center;
}

.loginBox .inputBox .inputText input:focus {
	box-shadow: 0 0 20px 0px #ffffff;
}

.loginBox .inputBox .inputButton {
	outline: none;
	border: 0;
	width: 200px;
	height: 30px;
	color: white;
	margin-top: 30px;
	border-radius: 20px;
	margin-left: 15px;
	background-image: linear-gradient(to right, #b8cbb8 0%, #b8cbb8 0%, #b465da 0%, #cf6cc9 33%, #ee609c 66%, #ee609c 100%);
}

.login .inputBox .inputButton:hover {
	box-shadow: 0 0 20px 0px #b465da;
}

.registBox::before {
	content: '';
	position: absolute;
	display: block;
	width: 100%;
	height: 300px;
	left: 0;
	top: 0;
	transform-origin: 70% 100%;
	transform: rotate(135deg);
	background-color: #ffffffcc;
	transition: 0.4s;
	z-index: 10;
}

.registBox .spanBox span {
	position: absolute;
	right: 5%;
	bottom: 10%;
	float: right;
	color: white;
	z-index: 1;
}
</style>
